Procedures with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their
position.
Public Sub SetCoordinates(ByVal x1 As Integer, ByVal y1 As Integer, ByVal z1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal z2 As Integer) ' Noncompliant
' ...
End Sub
The solution can be to:
- Split the procedure into smaller ones
'Each function does a part of what the original setCoordinates function was doing, so confusion risks are lower
Public Sub SetOrigin(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer)
' ...
End Sub
Public Sub SetSize(ByVal width As Integer, ByVal height As Integer, ByVal depth As Integer)
' ...
End Sub
- Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain
Public Type Point ' In geometry, Point is a logical structure to group data
X As Integer
Y As Integer
Z As Integer
End Type
This rule raises an issue when a procedure has more parameters than the provided threshold.